import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shouyin_app/pages/home/home.dart';

class HomeView extends StatelessWidget {
  const HomeView({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeController>(
      init: HomeController(),
      id: 'update_page',
      builder: (controller) => Container(
        color: Colors.green,
        child: Row(
          children: [
            _buildNavigationView(context,controller),
            const VerticalDivider(thickness: 1, width: 1,color: Colors.grey),
            _buildContentView(context,controller),
          ],
        ),
      ),
    );
  }

  Widget _buildNavigationView(BuildContext context, HomeController controller) {
    return Container(
      child: Column(
        children: [
          _buildUserView(context,controller),
          Expanded(child: NavigationRail(
            selectedIndex: controller.selectedIndex,
            onDestinationSelected: (int index) {
              controller.onSelected(index);
            },
            extended: controller.isExtended,
            useIndicator: false,
            minWidth: 80,
            minExtendedWidth: 120,
            // indicatorShape: RoundedRectangleBorder(
            //   borderRadius: BorderRadius.circular(10.0),
            //   side: BorderSide(color: Colors.yellow, width: 2.0),
            // ),
            destinations: [
              NavigationRailDestination(icon: Container(
                padding: EdgeInsets.symmetric(vertical: 8),
                alignment: Alignment.center,
                child: Column(
                  children: [
                    Icon(Icons.holiday_village),
                    Padding(padding: EdgeInsets.symmetric(vertical: 4)),
                    Text('栏目1')
                  ],
                ),
              ), label: SizedBox.shrink()),
              NavigationRailDestination(icon: Container(
                padding: EdgeInsets.symmetric(vertical: 8),
                alignment: Alignment.center,
                child: Column(
                  children: [
                    Icon(Icons.radar),
                    Padding(padding: EdgeInsets.symmetric(vertical: 4)),
                    Text('栏目2')
                  ],
                ),
              ), label: SizedBox.shrink()),
              NavigationRailDestination(icon: Container(
                padding: EdgeInsets.symmetric(vertical: 8),
                alignment: Alignment.center,
                child: Column(
                  children: [
                    Icon(Icons.earbuds),
                    Padding(padding: EdgeInsets.symmetric(vertical: 4)),
                    Text('栏目3')
                  ],
                ),
              ), label: SizedBox.shrink()),
              NavigationRailDestination(icon: Container(
                padding: EdgeInsets.symmetric(vertical: 8),
                alignment: Alignment.center,
                child: Column(
                  children: [
                    Icon(Icons.ac_unit_outlined),
                    Padding(padding: EdgeInsets.symmetric(vertical: 4)),
                    Text('栏目4')
                  ],
                ),
              ), label: SizedBox.shrink()),
            ],
          ))
        ],
      ),
    );
  }

  Widget _buildUserView(BuildContext context, HomeController controller) {
    return ConstrainedBox(
      constraints: BoxConstraints.tightFor(height: 220),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          IconButton(
            onPressed: () {
              controller.onExtended();
            },
            icon: Icon(controller.isExtended? Icons.menu: Icons.menu_open),
          ),
          Text('用户信息'),
        ],
      ),
    );
  }
  Widget _buildContentView(BuildContext context, HomeController controller) {
    return Expanded(
      child: Column(
        children: [
          _buildTopView(context,controller),
          _buildPageView(context,controller),
          _buildBottomView(context,controller)
        ],
      ),
    );
  }

  Widget _buildTopView(BuildContext context, HomeController controller) {
    return Container(
      height: 150,
      color: Colors.grey,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text('标题'),
          TextButton(onPressed: () {
            controller.goPutOrderPage(context);
          }, child: Text('主题')),
        ],
      ),
    );
  }

  _buildPageView(BuildContext context, HomeController controller) {
    return Expanded(child: PageView(
      controller: controller.pageController,
      physics: NeverScrollableScrollPhysics(),
      children: controller.pages,
    ));
  }

  Widget _buildBottomView(BuildContext context, HomeController controller) {
    return Container(
      height: 70,
      color: Colors.grey,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text('通知'),
          Text('时间'),
        ],
      ),
    );
  }


}
